﻿@using Contoso.Domain;
@model Contoso.Domain.Instructor

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Instructor</legend>

        @Html.HiddenFor(model => model.PersonID)

        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FirstMidName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstMidName)
            @Html.ValidationMessageFor(model => model.FirstMidName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.HireDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.HireDate)
            @Html.ValidationMessageFor(model => model.HireDate)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.OfficeAssignment.Location)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.OfficeAssignment.Location)
            @Html.ValidationMessageFor(model => model.OfficeAssignment.Location)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Courses)
        </div>
        <div class="editor-field">
            <table style="width: 100%">
                <tr>
                    @{
                        int cnt = 0;
                        List<Contoso.Domain.ViewModels.AssignedCourseData> courses = ViewBag.Courses;

                        foreach (var course in courses) {
                            if (cnt++ % 3 == 0) {
                                @:  </tr> <tr> 
                            }
                            @: <td> 
                                <input type="checkbox" 
                                       name="selectedCourses" 
                                       value="@course.CourseID" 
                                       @(Html.Raw(course.Assigned ? "checked=\"checked\"" : "")) /> 
                                @course.CourseID @:&nbsp; @course.Title
                            @:</td>
                        }
                        @: </tr>
                    }
            </table>
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
